<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/jsp/header.jsp" %>

<% String title = "全安药业信息综合系统后台登陆"; %>
<title><%=title %>
</title>
</head>

<!-- BEGIN BODY -->
<body class="lock" onkeydown="keyDown()">
<!-- ui-dialog -->
<div id="dialog2" title="Dialog Title" class="ui-dialog-content ui-widget-content">
    <p>修改不成功的提示</p>
</div>
<div id="dialog" title="Dialog Title" class="ui-dialog-content ui-widget-content">
    <p>修改成功的提示</p>
</div>

<form id="updatePassword" method="post">
    <div class="lock-header">
        <!-- BEGIN LOGO -->
        <a class="center" id="logo" href="javascript:void(0);">
            <img class="center" alt="logo" src="${pageContext.request.contextPath}/img/logo.png">
        </a>
        <!-- END LOGO -->
    </div>
    <div class="login-wrap">
        <div class="metro single-size red">
            <div class="locked">
                <i class="icon-lock"></i>
                <span>修改密码</span>
            </div>
        </div>
        <div class="metro double-size green">
            <div class="input-append lock-input">
                <input type="text" placeholder="请输入当前密码" id="passwordOld"  name="passwordOld">
                <div class="row" style="margin-top: 15px"><span>请输入当前密码</span></div>
            </div>
        </div>
        <div class="metro double-size yellow">
            <div class="input-append lock-input">
                <input type="password" placeholder="" id="passwordNew" name="passwordNew">
                <div class="row" style="margin-top: 15px;"><span >请输入新密码</span></div>
            </div>
        </div>
        <div class="metro single-size purple">
            <a href="javascript:void(0);" class="social-link" onclick="updatePassword()"> <i class="icon-gear"></i>
                <span>修 改</span>
            </a>
        </div>
    </div>
</form>


<script src="${pageContext.request.contextPath}/js/jquery-1.8.3.min.js"></script>
<script src="${pageContext.request.contextPath}/javascript/httpService.js"></script>
<!-- jQuery-UI插件相关js的引入 -->
<script src="${pageContext.request.contextPath}/jquery-ui-1.12.1/external/jquery/jquery.js"></script>
<script src="${pageContext.request.contextPath}/jquery-ui-1.12.1/jquery-ui.js"></script>
<!-- 自定义的script方法 -->
<script type="text/javascript">
    //回车登陆
    function keyDown() {
        //如果键盘按了回车
        if (event.keyCode == 13) {
            var params = $("#updatePassword").serialize();
            sendRequest(pageContextPath + "/user/updatePassword.do", params,
                function (responseJson) {
                    if (responseJson.data.error != null) {
                        $("#dialog2").html("");
                        var html = '<p>' + responseJson.data.error + '</p>';
                        $("#dialog2").html(html);
                        $("#dialog2").attr("class", "ui-dialog-content ui-widget-content");
                        $("#dialog2").dialog("open");
                    } else {
                        if (responseJson.data.message != null) {
                            $("#dialog").html("");
                            var html = '<p>' + responseJson.data.message + '</p>';
                            $("#dialog").html(html);
                            $("#dialog").attr("class", "ui-dialog-content ui-widget-content");
                            $("#dialog").dialog("open");
                        }
                    }
                });
        }
    }

    //点击修改
    function updatePassword() {
        var params = $("#updatePassword").serialize();
        sendRequest(pageContextPath + "/user/updatePassword.do", params,
            function (responseJson) {
                if (responseJson.data.error != null) {
                    $("#dialog2").html("");
                    var html = '<p>' + responseJson.data.error + '</p>';
                    $("#dialog2").html(html);
                    $("#dialog2").attr("class", "ui-dialog-content ui-widget-content");
                    $("#dialog2").dialog("open");
                } else {
                    if (responseJson.data.message != null) {
                        $("#dialog").html("");
                        var html = '<p>' + responseJson.data.message + '</p>';
                        $("#dialog").html(html);
                        $("#dialog").attr("class", "ui-dialog-content ui-widget-content");
                        $("#dialog").dialog("open");
                    }
                }
            });
    }

    //提示对话框
    $("#dialog2").dialog({
        autoOpen: false,
        width: 400,
        title: '<%=title%>',
        buttons: [
            {
                text: "知道了",
                click: function () {
                    $(this).dialog("close");
                }
            }
        ]
    });
    //成功 提示对话框
    $("#dialog").dialog({
        autoOpen: false,
        width: 400,
        title: '<%=title%>',
        buttons: [
            {
                text: "前往登录",
                click: function () {
                    $(this).dialog("close");
                    window.location.href = "${pageContext.request.contextPath}/user/index.do";
                }
            }
        ]
    });
</script>
<!-- END BODY -->
<script>
    $(function(){
        $("#passwordOld").val("请输入当前密码");
        $("#passwordNew").val("请输入新密码");
    });
</script>
</body>
</html>